package com.sskj.mine.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.MineRegisterActivity;


public class MineRegisterActivityPresenter extends BasePresenter<MineRegisterActivity> {

    // 获取短信验证码
    public void getCode(String mobile, String type) {
        httpService.sendSms(mobile, type).execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.sendCheckCodeSuccess();
                } else {
                    ToastUtil.showShort(httpData.getMsg());
                    mView.sendCheckCodeFail();
                }
            }

            @Override
            public void onError(Response<HttpData> response) {
                mView.sendCheckCodeFail();
                super.onError(response);
            }
        });
    }

    // 注册
    public void register(String mobile, String code, String opwd, String opwd1, String tjuser) {
        httpService.register(mobile, code, opwd, opwd1, tjuser).execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.registerSuccess();
                }
            }
        });
    }
}
